﻿if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('tb_article') and o.name = 'FK_TB_ARTICLE_CREATEBY_REFERENCE_TB_USER_ID')
alter table tb_article
   drop constraint FK_TB_ARTICLE_CREATEBY_REFERENCE_TB_USER_ID
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('tb_article') and o.name = 'FK_TB_ARTICLE_UPDATEBY_REFERENCE_TB_USER_ID')
alter table tb_article
   drop constraint FK_TB_ARTICLE_CREATEBY_REFERENCE_TB_USER_ID
go

if exists (select 1
            from  sysobjects
           where  id = object_id('tb_article')
            and   type = 'U')
   drop table tb_article
go

/*==============================================================*/
/* Table: tb_article                                            */
/*==============================================================*/
create table tb_article (
   Id                   int                  identity,
   Title_Zh_cn          nvarchar(200)        not null,
   Title_Zh_tw          nvarchar(200)        not null,
   Title_En_us          nvarchar(200)        not null,
   ClassId              int                  not null,
   TopClassId              int                  not null,
   Content_Zh_cn        ntext                not null default(''),
   Content_Zh_tw        ntext                not null default(''),
   Content_En_us        ntext                not null default(''),
   IsHot                bit                  not null default 0,
   HasAudited           bit                  not null default 0,
   PicUrl               nvarchar(255)        null,
   KeyWord_Zh_cn        nvarchar(500)        null,
   KeyWord_Zh_tw        nvarchar(500)        null,
   KeyWord_En_us        nvarchar(500)        null,
   UpdateDate           datetime             null,
   UpdateBy             int                  null,
   CreateDate           datetime             null,
   CreateBy             int                  null,
   constraint PK_TB_ARTICLE primary key (Id)
)
go

alter table tb_article
   add constraint FK_TB_ARTICLE_CREATEBY_REFERENCE_TB_USER_ID foreign key (Id)
      references tb_user (Id)
go

alter table tb_article
   add constraint FK_TB_ARTICLE_UPDATEBY_REFERENCE_TB_USER_ID foreign key (Id)
      references tb_user (Id)
go
